home *** CD-ROM | disk | FTP | other *** search
- /* ------------------------------------------------------------------------------
- | FILE NAME: ListList.h
- |
- | DOCUMENT: [186.5]
- |
- | PURPOSE: To permit use of list system functions by other programs.
- |
- | DESCRIPTION: A list of extern prototypes in #include-able format.
- |
- | NOTE:
- |
- | HISTORY: 01.12.89 Created by Lee Malone
- | 01.30.89 Added SortListAlphabetically
- | 02.01.89 Added Item, LIST structs
- | 02.02.89 Added DeleteAllItemsFromAListThatMatchAAddressOfData
- | 02.16.89 Split of stack functions to stacks.h
- | 03.07.89 Added , Byte->Byte, Truth->Truth
- | 07.09.89 Changed structure of LIST and Item -- added status field,
- | datatype field, name field
- | 07.11.89 Added Name field to Item
- | 10.11.89 Remove Name fields and DataTypeID fields
- | 02.03.93 Copied from lists.h
- | 10.25.93 Revised to conform to Focus usage.
- | 11.22.93 Release 5.0
- |----------------------------------------------------------------------------- */
-
- #ifndef _LISTS_H_
- #define _LISTS_H_
-
- #include <DataSize.h>
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
-
- #include "Strings.h"
-
- /*************************************************************/
- /* T H E I T E M R E C O R D */
- /*************************************************************/
-
- typedef struct ItemRecord
- {
- struct ItemRecord *AddressOfNextItem;
-
- struct ItemRecord *AddressOfPriorItem;
-
- AddressOfByte AddressOfData; /* Where the data is for this item. */
-
- Pair ItemMark; /* Pair used because 'C' */
- /* pads with extra byte */
- /* anyway for even alignment.*/
- } Item, *AddressOfItem;
-
- /*
- * Item Mark Field format:
- *
- * Bit 0 = 1 if marked by user, eg. to mark selected items
- *
- * Bit 1 = 1 if AddressOfData is the address of a list record,
- * implemented in 'Trees.c' extension -- not included.
- *
- * Bit 2-15 = available to user
- */
-
- /* Mark field masks: */
- #define Marked 1
- #define DataIsList (1<<1) /* Used exclusively by 'Trees.c' */
-
- /*------------------------------------------------------------
- | NAME: GetItemDataAddress
- |
- | PURPOSE: To get the address of the data for the given item.
- |
- | DESCRIPTION:
- |
- | EXAMPLE: WhereDataIs = GetItemDataAddress(AnItem);
- |
- | NOTE:
- |
- | ASSUMES:
- |
- | HISTORY: 10.26.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define GetItemDataAddress(I) (I->AddressOfData)
-
- /*------------------------------------------------------------
- | NAME: GetNextItem
- |
- | PURPOSE: To get the address of the item following the given
- | item.
- |
- | DESCRIPTION: If no item follows the given item then 0 is
- | returned as the address.
- |
- | EXAMPLE:
- |
- | NOTE:
- |
- | ASSUMES:
- |
- | HISTORY: 10.26.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define GetNextItem(I) (I->AddressOfNextItem)
-
- /*------------------------------------------------------------
- | NAME: GetPriorItem
- |
- | PURPOSE: To get the address of the item preceeding the given
- | item.
- |
- | DESCRIPTION: If no item preceeds the given item then 0 is
- | returned as the address.
- |
- | EXAMPLE:
- |
- | NOTE:
- |
- | ASSUMES:
- |
- | HISTORY: 10.26.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define GetPriorItem(I) (I->AddressOfPriorItem)
-
- /*------------------------------------------------------------
- | NAME: GetItemMark
- |
- | PURPOSE: To get the mark code of the given item.
- |
- | DESCRIPTION:
- |
- | EXAMPLE:
- |
- | NOTE:
- |
- | ASSUMES:
- |
- | HISTORY: 10.26.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define GetItemMark(I) (I->ItemMark)
-
- /*------------------------------------------------------------
- | NAME: PutItemDataAddress
- |
- | PURPOSE: To put the data address into the given item.
- |
- | DESCRIPTION:
- |
- | EXAMPLE:
- |
- | NOTE:
- |
- | ASSUMES:
- |
- | HISTORY: 10.26.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define PutItemDataAddress(I,D) (I->AddressOfData = D)
-
- /*------------------------------------------------------------
- | NAME: PutItemMark
- |
- | PURPOSE: To put the item mark code into the given item.
- |
- | DESCRIPTION:
- |
- | EXAMPLE:
- |
- | NOTE:
- |
- | ASSUMES:
- |
- | HISTORY: 10.27.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define PutItemMark(I,S) (I->ItemMark = S)
-
- /*------------------------------------------------------------
- | NAME: PutNextItem
- |
- | PURPOSE: To put the item address of the following item into
- | given item.
- |
- | DESCRIPTION:
- |
- | EXAMPLE:
- |
- | NOTE:
- |
- | ASSUMES:
- |
- | HISTORY: 10.27.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define PutNextItem(I,N) (I->AddressOfNextItem = N)
-
- /*------------------------------------------------------------
- | NAME: PutPriorItem
- |
- | PURPOSE: To put the item address of the preceeding item into
- | the given item.
- |
- | DESCRIPTION:
- |
- | EXAMPLE:
- |
- | NOTE:
- |
- | ASSUMES:
- |
- | HISTORY: 10.27.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define PutPriorItem(I,P) (I->AddressOfPriorItem = P)
-
- /*------------------------------------------------------------
- | NAME: TheDataAddress
- |
- | PURPOSE: To refer to the address of the data associated with
- | the current item.
- |
- | DESCRIPTION:
- |
- | EXAMPLE: a = TheDataAddress;
- |
- | NOTE: The address of the current item is held in 'TheItem'.
- |
- | ASSUMES:
- |
- | HISTORY: 10.27.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define TheDataAddress (TheItem->AddressOfData)
-
- /*------------------------------------------------------------
- | NAME: TheNextItem
- |
- | PURPOSE: To refer to the address of the item following
- | the current item.
- |
- | DESCRIPTION: If no item follows the current item then 0 is
- | returned as the address.
- |
- | EXAMPLE: next = TheNextItem;
- |
- | NOTE: The address of the current item is held in 'TheItem'.
- |
- | ASSUMES:
- |
- | HISTORY: 10.27.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define TheNextItem (TheItem->AddressOfNextItem)
-
- /*------------------------------------------------------------
- | NAME: ThePriorItem
- |
- | PURPOSE: To refer to the address of the item preceeding the
- | current item.
- |
- | DESCRIPTION: If no item preceeds the current item then 0 is
- | returned as the address.
- |
- | EXAMPLE:
- |
- | NOTE: The address of the current item is held in 'TheItem'.
- |
- | ASSUMES:
- |
- | HISTORY: 10.26.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define ThePriorItem (TheItem->AddressOfPriorItem)
-
- /*------------------------------------------------------------
- | NAME: TheItemMark
- |
- | PURPOSE: To refer to the mark code of the current item.
- |
- | DESCRIPTION:
- |
- | EXAMPLE: mark = TheItemMark;
- |
- | NOTE: The address of the current item is held in 'TheItem'.
- |
- | ASSUMES:
- |
- | HISTORY: 10.26.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define TheItemMark (TheItem->ItemMark)
-
- /*************************************************************/
- /* T H E L I S T R E C O R D */
- /*************************************************************/
-
- typedef struct ListRecord
- {
- AddressOfItem AddressOfFirstItem;
- AddressOfItem AddressOfLastItem;
- Quad ItemCount;
- Pair ListMark; /* Pair used because C pads */
- /* with extra byte for even */
- /* alignment anyway. */
- } List, *AddressOfList;
-
- /*
- * List Mark Field format:
- *
- * Bit 0 = 1 if marked by user, eg. to mark selected lists
- *
- * Bit 1-15 = available to user
- */
-
- /* List Mark Bit field Masks */
- /* #define Marked 1 -- defined above */
-
- /*------------------------------------------------------------
- | NAME: AddToListItemCount
- |
- | PURPOSE: To add a value to the item count into the given
- | list record.
- |
- | DESCRIPTION:
- |
- | EXAMPLE: AddToListItemCount(NameList,1);
- |
- | NOTE:
- |
- | ASSUMES:
- |
- | HISTORY: 10.28.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define AddToListItemCount(L,C) (L->ItemCount += (Quad) C)
-
- /*------------------------------------------------------------
- | NAME: GetFirstItemOfList
- |
- | PURPOSE: To get the address of the first item of the
- | given list.
- |
- | DESCRIPTION:
- |
- | EXAMPLE: AnItem = GetFirstItemOfList(NameList);
- |
- | NOTE:
- |
- | ASSUMES:
- |
- | HISTORY: 10.28.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define GetFirstItemOfList(L) (L->AddressOfFirstItem)
-
- /*------------------------------------------------------------
- | NAME: GetLastItemOfList
- |
- | PURPOSE: To get the address of the last item of the
- | given list.
- |
- | DESCRIPTION:
- |
- | EXAMPLE: AnItem = GetLastItemOfList(NameList);
- |
- | NOTE:
- |
- | ASSUMES:
- |
- | HISTORY: 10.27.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define GetLastItemOfList(L) (L->AddressOfLastItem)
-
- /*------------------------------------------------------------
- | NAME: GetListItemCount
- |
- | PURPOSE: To get the count of items in the given list.
- |
- | DESCRIPTION:
- |
- | EXAMPLE: HowMany = GetListItemCount(NameList);
- |
- | NOTE:
- |
- | ASSUMES:
- |
- | HISTORY: 10.27.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define GetListItemCount(L) (L->ItemCount)
-
- /*------------------------------------------------------------
- | NAME: GetListMark
- |
- | PURPOSE: To get the mark code of the given list.
- |
- | DESCRIPTION:
- |
- | EXAMPLE: mark = GetListMark(NameList);
- |
- | NOTE:
- |
- | ASSUMES:
- |
- | HISTORY: 10.28.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define GetListMark(L) (L->ListMark)
-
- /*------------------------------------------------------------
- | NAME: PutFirstItemOfList
- |
- | PURPOSE: To put the address of the first item into the
- | given list record.
- |
- | DESCRIPTION:
- |
- | EXAMPLE: PutFirstItemOfList(NameList,AnItem);
- |
- | NOTE:
- |
- | ASSUMES:
- |
- | HISTORY: 10.28.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define PutFirstItemOfList(L,I) (L->AddressOfFirstItem = I)
-
- /*------------------------------------------------------------
- | NAME: PutLastItemOfList
- |
- | PURPOSE: To put the address of the last item into the
- | given list record.
- |
- | DESCRIPTION:
- |
- | EXAMPLE: PutLastItemOfList(NameList,AnItem);
- |
- | NOTE:
- |
- | ASSUMES:
- |
- | HISTORY: 10.28.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define PutLastItemOfList(L,I) (L->AddressOfLastItem = I)
-
- /*------------------------------------------------------------
- | NAME: PutListItemCount
- |
- | PURPOSE: To put the item count into the given list record.
- |
- | DESCRIPTION:
- |
- | EXAMPLE: PutListItemCount(NameList,5);
- |
- | NOTE:
- |
- | ASSUMES:
- |
- | HISTORY: 10.28.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define PutListItemCount(L,C) (L->ItemCount = C)
-
- /*------------------------------------------------------------
- | NAME: PutListMark
- |
- | PURPOSE: To put the list mark code into the given list.
- |
- | DESCRIPTION:
- |
- | EXAMPLE: PutListMark(NameList,Marked);
- |
- | NOTE:
- |
- | ASSUMES:
- |
- | HISTORY: 10.27.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define PutListMark(L,M) (L->ListMark = M)
-
-
- /*------------------------------------------------------------
- | NAME: TheItemCount
- |
- | PURPOSE: To refer to the item count of the current list.
- |
- | DESCRIPTION:
- |
- | EXAMPLE: CountOfItems = TheItemCount;
- |
- | NOTE: The address of the current list is held in 'TheList'.
- |
- | ASSUMES:
- |
- | HISTORY: 10.27.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define TheItemCount (TheList->ItemCount)
-
- /*------------------------------------------------------------
- | NAME: TheFirstItem
- |
- | PURPOSE: To refer to the address of the first item of the
- | current list.
- |
- | DESCRIPTION:
- |
- | EXAMPLE: AnItem = TheFirstItem;
- |
- | NOTE: The address of the current list is held in 'TheList'.
- |
- | ASSUMES:
- |
- | HISTORY: 10.27.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define TheFirstItem (TheList->AddressOfFirstItem)
-
- /*------------------------------------------------------------
- | NAME: TheLastItem
- |
- | PURPOSE: To refer to the address of the last item of the
- | current list.
- |
- | DESCRIPTION:
- |
- | EXAMPLE: AnItem = TheLastItem;
- |
- | NOTE: The address of the current list is held in 'TheList'.
- |
- | ASSUMES:
- |
- | HISTORY: 10.27.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define TheLastItem (TheList->AddressOfLastItem)
-
- /*------------------------------------------------------------
- | NAME: TheListMark
- |
- | PURPOSE: To refer to the mark code of the current list.
- |
- | DESCRIPTION:
- |
- | EXAMPLE: mark = TheListMark;
- |
- | NOTE: The address of the current list is held in 'TheList'.
- |
- | ASSUMES:
- |
- | HISTORY: 10.27.93 by Lee Malone
- |
- ------------------------------------------------------------*/
- #define TheListMark (TheList->ListMark)
-
-
-
- /*************************************************************/
- /* */
- /* D I R E C T A C C E S S T A B L E */
- /* */
- /* A Direct Access Table is just an array of item record */
- /* addresses. */
- /* */
- /* Normally a linked list is accessed sequentially but there */
- /* are some situations where direct access of items in any */
- /* order is needed. A direct access table can be */
- /* made from a list to give direct access to any item via */
- /* its offset in the direct access table. */
- /* */
- /* For speed, some sorting and searching procedures first */
- /* build a direct access table if the number of items in the */
- /* list is above a certain threshold. */
- /* */
- /*************************************************************/
-
- extern Quad DirectAccessTableThreshold;
- /* Quantity of items, above which a direct */
- /* access table is used to sort them. */
-
-
- typedef AddressOfItem *AddressOfAddressOfItem;
-
- extern Quad MaximumLists;
- extern Quad MaximumItems;
-
- /* Where lists and items are stored in memory. */
- extern AddressOfList ListSpace;
- extern AddressOfItem ItemSpace;
-
- extern Quad CountOfFreeLists;
- extern Quad CountOfFreeItems;
- extern Quad MaxCountOfLists;
- extern Quad MaxCountOfItems;
- extern AddressOfList FirstFreeList;
- extern AddressOfItem FirstFreeItem;
- extern AddressOfList TheList;
- extern AddressOfItem TheItem;
- extern Quad TheListStack[];
- extern Quad TheListStackIndex;
- extern Pair TheListSystemIsSetUp;
-
- /* -------------------PROTOTYPES----------------------------- */
- /*
- Operations implemented using the preceeding #define
- statements are included below within comments for reference.
- */
-
- /* Nothing AddToListItemCount(AddressOfList,Quad); */
-
- AddressOfAddressOfItem BuildDirectAccessTableForList(AddressOfList);
- Nothing CleanUpTheListSystem(Nothing);
- AddressOfList CreateList(Nothing);
- AddressOfItem CreateItem(Nothing);
- AddressOfItem CreateItemForData(AddressOfByte);
-
- Nothing DeleteAllReferencesToData(AddressOfList,AddressOfByte);
- AddressOfItem DeleteFirstReferenceToData(AddressOfList,AddressOfByte);
- Nothing DeleteList(AddressOfList);
- Nothing DeleteListOfDynamicData(AddressOfList);
- Nothing DeleteItem(AddressOfItem);
- Nothing DeleteMarkedItems(AddressOfList);
-
- AddressOfList DuplicateList(AddressOfList);
- AddressOfList DuplicateMarkedItems(AddressOfList);
- Nothing ExchangeItems(AddressOfList,AddressOfItem,AddressOfItem);
- AddressOfItem ExtractItemFromList(AddressOfList,AddressOfItem);
- AddressOfItem ExtractFirstItemFromList(AddressOfList);
- AddressOfItem ExtractLastItemFromList(AddressOfList);
- AddressOfList ExtractMarkedItems(AddressOfList);
- AddressOfItem ExtractTheItem(Nothing);
- AddressOfItem FindFirstItemLinkedToData(AddressOfList,AddressOfByte);
- AddressOfItem FindFirstMatchingItem(AddressOfList, Pair, Pair, AddressOfByte);
- AddressOfItem FindPlaceInOrderedList(AddressOfList,
- AddressOfByte,
- AddressOfComparisonProcedure);
- AddressOfAddressOfItem FindPlaceInOrderedDirectAccessTable(AddressOfAddressOfItem,
- Quad,
- AddressOfByte,
- AddressOfComparisonProcedure);
- AddressOfItem FindNextMatchingItem(AddressOfList,
- AddressOfItem,
- Pair,
- Pair,
- AddressOfByte);
- AddressOfItem FindFirstMarkedItem(AddressOfList);
- AddressOfItem FindFirstUnMarkedItem(AddressOfList);
- Quad FindIndexOfFirstMarkedItem(AddressOfList);
-
- /* Operations used to get values from Item records: */
- /* AddressOfByte GetItemDataAddress(AddressOfItem); */
- /* AddressOfItem GetNextItem(AddressOfItem); */
- /* AddressOfItem GetPriorItem(AddressOfItem); */
- /* Pair GetItemMark(AddressOfItem); */
-
- /* Operations used to get values from List records: */
- /* Quad GetListItemCount(AddressOfList); */
- /* AddressOfItem GetFirstItemOfList(AddressOfList); */
- /* AddressOfItem GetLastItemOfList(AddressOfList); */
- /* Pair GetListMark(AddressOfList); */
-
- Nothing InsertItemAfterItemInList(AddressOfList,AddressOfItem,AddressOfItem);
- Nothing InsertItemBeforeItemInList(AddressOfList,AddressOfItem,AddressOfItem);
- Nothing InsertItemFirstInList(AddressOfList,AddressOfItem);
- Nothing InsertItemLastInList(AddressOfList,AddressOfItem);
-
- AddressOfItem InsertDataAfterItemInList(AddressOfList,AddressOfItem,AddressOfByte);
- AddressOfItem InsertDataBeforeItemInList(AddressOfList,AddressOfItem,AddressOfByte);
- AddressOfItem InsertDataFirstInList(AddressOfList,AddressOfByte);
- AddressOfItem InsertDataInOrderedList(AddressOfList,AddressOfByte,
- AddressOfComparisonProcedure);
- AddressOfItem InsertDataLastInList(AddressOfList,AddressOfByte);
-
- Truth IsAnyItemMarkedInList(AddressOfList);
- Truth IsAnyItemsInList(AddressOfList);
- Truth IsItemAlone(AddressOfItem);
- Truth IsItemCreationPossible(Nothing);
- Truth IsItemFirst(AddressOfItem);
- Truth IsItemLast(AddressOfItem);
- Truth IsItemMarked(AddressOfItem);
- Truth IsListCreationPossible(Nothing);
- Truth IsListMarked(AddressOfList);
- Truth IsTheDataMatching(Pair,Pair,AddressOfByte);
-
- Nothing JoinLists(AddressOfList,AddressOfList);
- Nothing MarkItem(AddressOfItem);
- Nothing MarkItemAsFirst(AddressOfItem);
- Nothing MarkItemAsLast(AddressOfItem);
- Nothing MarkList(AddressOfList);
- Nothing MarkListAsEmpty(AddressOfList);
- Nothing OutputListOfStrings(AddressOfList, FILE*);
- Nothing OutputListSystemStatus(FILE*);
- Nothing PullTheItem(Nothing);
- Nothing PullTheList(Nothing);
- Nothing PullTheListAndItem(Nothing);
- Nothing PushTheList(Nothing);
- Nothing PushTheListAndItem(Nothing);
- Nothing PushTheItem(Nothing);
-
- /* Operations used to put values into Item records: */
- /* Nothing PutItemDataAddress(AddressOfItem,AddressOfByte); */
- /* Nothing PutItemMark(AddressOfItem,Pair); */
- /* Nothing PutNextItem(AddressOfItem,AddressOfItem); */
- /* Nothing PutPriorItem(AddressOfItem,AddressOfItem); */
-
- /* Operations used to put values into List records: */
- /* Nothing PutFirstItemOfList(AddressOfList,AddressOfItem); */
- /* Nothing PutLastItemOfList(AddressOfList,AddressOfItem); */
- /* Nothing PutListItemCount(AddressOfList,Quad); */
- /* Nothing PutListMark(AddressOfList,Pair); */
-
- Nothing ReorderListToMatchDirectAccessTable(AddressOfList,AddressOfAddressOfItem);
- Nothing ReverseList(AddressOfList);
- Nothing SetUpTheListSystem(Quad, Quad);
- Nothing SortDirectAccessTable(AddressOfAddressOfItem,
- Quad,
- AddressOfComparisonProcedure);
- Nothing SortList(AddressOfList,AddressOfComparisonProcedure);
- Nothing SortListAlphabetically(AddressOfList);
- Nothing SortListDescending(AddressOfList,AddressOfComparisonProcedure);
- Nothing SortListViaDirectAccessTable(AddressOfList,AddressOfComparisonProcedure);
- Nothing SortShortList(AddressOfList,AddressOfComparisonProcedure);
-
- /* Fields of the current item: */
- /* AddressOfByte TheDataAddress; */
- /* AddressOfItem TheNextItem; */
- /* AddressOfItem ThePriorItem; */
- /* Pair TheItemMark; */
-
- /* Fields of the current list: */
- /* Quad TheItemCount; */
- /* AddressOfItem TheFirstItem; */
- /* AddressOfItem TheLastItem; */
- /* Pair TheListMark; */
-
- Nothing ToFirstItem(Nothing);
- Nothing ToLastItem(Nothing);
- Nothing ToNextItem(Nothing);
- Nothing ToPriorItem(Nothing);
- Nothing UnMarkAllItemsInList(AddressOfList);
- Nothing UnMarkList(AddressOfList);
- Nothing UnMarkItem(AddressOfItem);
-
-
- #endif